package com.xxx.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.fastjson.JSONObject;
import com.xxx.springboot.exception.ControllerExceptionUtil;

/**
 * Sentinel限流测试Controller
 * https://blog.csdn.net/qq_27641935/article/details/95170252
 */
@Controller
public class SentinelController {

	@RequestMapping(value = "/query", method = RequestMethod.GET)
	@SentinelResource(value = "/query", entryType= EntryType.IN, blockHandler = "queryExceptionHandler", blockHandlerClass = {ControllerExceptionUtil.class})
	@ResponseBody
	public String query(@RequestParam(value = "appid", required = true) Integer appid,
                         @RequestParam(value = "idfa", required = true) String idfa){
	     JSONObject obj = new JSONObject();
	     try {
	         int ret = 0;
	         obj.put(idfa,ret);
	     } catch (Exception e){
	         e.printStackTrace();
	     }
	     return obj.toJSONString();
	}
}
